import App from './App'
import { $http } from '@escook/request-miniprogram'
import store from './store/store'
$http.baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
uni.$http = $http

uni.addInterceptor('request',{
	invoke(args){
		args.data = { isLoading: true, ...args.data }
		if(args.data.isLoading) uni.showLoading({title: '数据加载中...'})
		if(args.url.indexOf('/my/') !== -1){
			args.header = {
				Authorization: store.state.m_user.token
			}
		}
	},
	complete(res){
		uni.hideLoading()
	},
	
})

// 封装弹窗
uni.$showMsg = function(title='数据加载失败',icon='error',duration=1500){
	uni.showToast({
		title,
		icon,
		duration
	})
}

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App,
  store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app,
	store
  }
}
// #endif